package com.cos.supplier.controller;

import com.cos.common.entity.Student;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: COS
 * @time: 2022/4/27 14:34
 * @description:
 */
@RestController
@RequestMapping("/sup")
public class SupplierController {
    @Value("${server.port}")
    String port;

    @GetMapping("/getData")
    public String getData() {
        System.out.println(10/0);
        return "这个就是你想要的的数据:" + port;
    }

    /**
     * @author: COS
     * @return:
     * @time: 2022/4/28 10:19
     * @description: 如果是单个参数时推荐使用 路径参数
     */
    @GetMapping("/getById/{id}")
    public Student getStudentById(@PathVariable("id") Integer id) {
        return new Student(id, Math.random()*1000+"", "男");
    }
    //?
    @GetMapping("/getStudent")
    public Student getStudent(@RequestParam(value = "sno") Integer id,
                              @RequestParam("name")String name,
                              @RequestParam String sex) {
        return new Student(id, name, sex);
    }
    @PostMapping("/addStudent")
    public Student addStudent(@RequestBody Student student) {
        return student;
    }

    @GetMapping("/getStuList")
    public List<Student> getStuList() {
        List<Student> studentList= new ArrayList<>();
        studentList.add(new Student(1, "张三", "男"));
        studentList.add(new Student(2, "李四", "女"));
        studentList.add(new Student(3, "王五", "男"));
        return studentList;
    }
}
